package com.cong.juc;

import java.util.concurrent.CyclicBarrier;

/**
 * @author cong
 * <p>
 * created on 2021/3/31 上午10:31
 */
public class CycllicBarrierDemo {

    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(7, () -> System.out.println("over"));
        for (int i = 1; i <= 7; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"\t 已完成");
                try {
                    //先到的被阻塞，完成之后再继续
                    cyclicBarrier.await();
                }catch (Exception e){
                    e.printStackTrace();
                }
            },String.valueOf(i)).start();
        }
    }
}
